/**
 * 
 */
package com.ginger.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ginger.model.User;

/**
 * @Description: 用户控制器
 * @author 姜锋
 * @date 2018年6月4日 下午8:38:18
 * @version V1.0
 */
@RestController
public class UserController {
	@PostMapping(value = "subLogin", produces = "application/json;charset=utf-8")
	public String subLogin(User user) {
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword());
		try {
			subject.login(token);
		} catch (Exception e) {
		}
		return "success";
	}
	@RequiresRoles("admin")
	@GetMapping("getAdminInfo")
	public User getAdminInfo(User user) {
		return user;
	}
	
	@RequiresRoles("user:query,admin:manager")
	@GetMapping("getUserInfo")
	public User getUserInfo(User user) {
		return user;
	}
}
